/**
 *
 * @author Faith
 */
public class DingPhilosophers {
    private Object[] forks;
    private Philosopher[] phr;

    private DingPhilosophers(int num){
        phr = new Philosopher[num];
        forks = new Object[num];
        for(int i=0; i < num; i++){
            forks[i] = new Object();
            if(i == 0){
                phr[0] = new Philosopher(i, i+1, i, forks);
            }else{
                phr[i] = new Philosopher(i, i, (i+1)%num, forks);
            }
        }

    }

    public void startEating() throws InterruptedException{
        for(int i= 0; i < phr.length; i++){
            phr[i].start();
        }
//        phr[0].join(); // suspend main thread until first philosopher stops eating, which will never happen
    }

    public static void main(String[] args){
        try{
            DingPhilosophers dp = new DingPhilosophers(5);
            dp.startEating();
        }catch(InterruptedException e){
        }
    }
}
